﻿using Credera.Theta.Component;
using Credera.Theta.Component.Writers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Credera.Theta.API
{
    public abstract class InputCommand
    {
        private InterceptWriter _nullWriter = null;
        private IHostInterface _interface = null;

        public string ActiveParameterSet { get; internal set; }
       
        [Switch]
        [Synopsis("If present, output sent to the Verbose HostWriter will be written to the console.")]
        public SwitchParameter Verbose { get; set; }

        [Switch]
        [Synopsis("If present, output sent to the Debug HostWriter will be written to the console.")]
        public SwitchParameter Debug { get; set; }

        protected InputCommandOutputCollection Out { get; private set; }

        protected CommandCollection RegisteredCommands { get { return this._interface == null ? null : this._interface.Commands; } }

        internal void InstallInterfaceServices(IHostInterface hostInterface)
        {
            this._interface = hostInterface;

            this.Out = new InputCommandOutputCollection(
                this._interface != null ? this._interface.Out.Standard : this._nullWriter,
                this._interface != null ? this._interface.Out.Warning : this._nullWriter,
                this._interface != null ? this._interface.Out.Error : this._nullWriter,
                this.Debug.IsPresent && this._interface != null ? this._interface.Out.Debug : this._nullWriter,
                this.Verbose.IsPresent && this._interface != null ? this._interface.Out.Verbose : this._nullWriter,
                this._interface != null ? this._interface.Out.Accent1 : this._nullWriter,
                this._interface != null ? this._interface.Out.Accent2 : this._nullWriter,
                this._interface != null ? this._interface.Out.Accent3 : this._nullWriter,
                this._interface != null ? this._interface.Out.Accent4 : this._nullWriter,
                this._interface != null ? this._interface.Out.Accent5 : this._nullWriter);
        }

        public abstract void Invoke(CommandInvocationContext context);

        public virtual List<string> GetDetailsDocumentation() { return null; }
        public virtual List<string> GetExamplesDocumentation() { return null; }

        protected string Prompt(string prompt)
        {
            return this._interface.Prompt(prompt);
        }

        protected InputCommand()
        {
            this._nullWriter = new NullWriter();
        }
    }
}
